package com.hehua.FactoryMethod;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;

/**
 * 获取xml配置文件值
 */
public class XmlUtil{
    public static Object getBean() throws Exception{
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc;
        doc = builder.parse(new File("src//com//hehua//FactoryMethod//FactoryMethod.xml"));
        NodeList tagName = doc.getElementsByTagName("className");
        String nodeValue = tagName.item(0).getFirstChild().getNodeValue();
        Class<?> aClass = Class.forName(nodeValue);
        Object instance = aClass.newInstance();
        return instance;
    }
}
